<?php
namespace Adminx\Controller;

class OptionController extends AdminController {

	#列表
	public function index() {
		$list = M('OptionCate')->select();
		$this->assign('list',$list);
		$this->display();
	}

	#添加
	public function add() {
		if($_POST){
    		$this->all_add('OptionCate',U('Option/index'));
    	}else{
			$this->display();
		}
	}

	#编辑
	public function edit() {
		if($_POST){
    		$this->all_save('OptionCate',U('Option/index'));
    	}else{
			$id = (int) $_GET['id'];
			if (!isset ($id)) {
				$this->error('参数错误');
			}
			$obj = M('OptionCate');
			$map['id']=$id;
			$list = $obj->where($map)->find();
			if (!$list) {
				$this->error('信息不存在');
			} else {
				$this->assign('list', $list);
				$this->display();
			}
		}		
	}


	#删除
	public function del() {
		$id=I('post.selectedids');
		if($id==''){
			$this->error('您没有选择任何信息！');
		}else{
			foreach ($id as $v) {
				$obj = M('OptionCate');
				$where['id'] = $v;
				$obj->where($where)->delete();
				M('OptionItem')->where('cate='.$v)->delete();
			}
	        $this->success('操作成功',U('Option/index'));
		}
	}
}
?>